package com.metaera.app.ui.adapters;

import android.content.Context;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.data.model.MorningPostResponse;
import com.metaera.app.ui.activities.ArticleDetailsActivity;
import com.metaera.app.utils.image.GlideApp;

import androidx.annotation.NonNull;

public class MorningPostAdapter extends BaseQuickAdapter<MorningPostResponse, BaseViewHolder> {

    public MorningPostAdapter() {
        super(R.layout.item_quick_recommend_article);

        setOnItemClickListener((adapter, view, position) -> {
            Context context = view.getContext();
            context.startActivity(ArticleDetailsActivity.newInstance(context, getItem(position).getId()));
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, MorningPostResponse item) {
        holder.setText(R.id.tv_article_title, item.getTitle())
                .setText(R.id.tv_article_author_date, item.getAuthor().getNickname() + " " + item.getRelease_time());

        ImageView ivArticleCover = holder.getView(R.id.iv_article_cover);
        GlideApp.with(ivArticleCover)
                .load(item.getPic())
                .miniThumb()
                .into(ivArticleCover);
    }
}
